package it.lefo.dateReminder.helper;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

/**
 * @author LEFO
 * Utilities Class
 * 
 */
public class Utilities {
	
	private final static String numPattern = "(\\d{3})?\\d{3}\\d{4}";
	
	/**
	 * Try to convert a String to a Date
	 * @param date as string
	 * @return Date or Null
	 */
	public static Date StringToDate(String date){
		Date dt = new Date();
		DateFormat formatter = new SimpleDateFormat("dd/MM/yy");
		try {
			dt = formatter.parse(date);
		} catch (ParseException e) {
			dt = null;
		}
		
		return dt;
	}
	
	/**
	 * Try to convert a Date to String
	 * @param date
	 * @param format (Ex: "dd/MM/yyyy")
	 * @return String or Null
	 */
	public static String DateToString(Date date, String format){
		DateFormat formatter = new SimpleDateFormat(format);	
		String dateAsString;
		try{
			dateAsString = formatter.format(date).toString();
		}catch(Exception e){
			dateAsString = "";
		}
		return dateAsString;
	}
	
	public static boolean isAValidPhoneNumber(String pnNum){
		return pnNum.matches(numPattern);
	}
}
